{include file="index/_meta" /}
<title>我的发布</title>
<style>
    .van-card__title {
        font-size: 1rem;
        color: #333;
        font-weight: bold;
    }

    .van-ellipsis {
        white-space: normal;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .van-card__desc {
        max-height: 40px;
    }
</style>
</head>
<body>
<div id="app">

    <van-nav-bar
            title="我的发布"
            left-text="返回"
            left-arrow
            @click-left="window.history.back();"
    ></van-nav-bar>

    <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            :immediate-check="no"
            @load="onload"
    >
        <div v-for="(item,index) in goodsQiangList" :key="index" style="padding: 5px">
            <van-card
                    :price="item.price"
                    :origin-price="item.original_price"
                    :desc="item.desc"
                    :title="item.title"
                    offset="70"
                    @click="jumpDetail(item.id)"
            >
                <template #thumb v-if="item.img_thumb">
                    <img :src="item.img_thumb" style="width: 100%;">
                </template>
                <template #tags>
                    <van-tag plain type="danger">{{item.forum_cate_name}}</van-tag>
                </template>
                <template #price>
                    发布时间：{{item.create_time}}
                </template>
                <template #footer v-if="item.user_id == user_id">
                    <van-button size="mini" @click.stop="edit(item.id)">编辑</van-button>
                    <van-button size="mini" @click.stop="del(item.id,index)">删除</van-button>
                </template>
            </van-card>
        </div>
    </van-list>

</div>
{include file="index/_share" /}
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                carousel: [],
                // 下拉刷新
                isLoading: false,
                // 上拉加载
                loading: false,
                finished: false,
                goodsQiangList: [],
                page: 0,
                last_page: 1,
                limit: 10,
                yes: true,
                no: false,
                keywords: '',
                district: '定位中',
                active: 2,
                user_id: "{$Think.session.wechat.id}",
                shopCateList:[],
                SwipeLength:1,
                forum_cate_id:'',
            }
        },
        created() {
            let that = this
            this.getShopCate()
            that.onload()
        },
        methods: {
            jumpSearch() {
                window.location.href = "{:url('index/search')}"
            },
            // 获取店铺分类
            getShopCate(){
                let that = this;
                axios.post("{:url('forum/getForumCateswipe')}").then(function (ret) {
                    that.shopCateList = ret.data.data
                    that.SwipeLength = Math.ceil(that.shopCateList.length/8)+1
                })
            },
            onload() {
                this.loading = true
                this.page++
                if (this.last_page < this.page) {
                    this.finished = true
                } else {
                    this.getGoodsList()
                }
            },
            getGoodsList() {
                let that = this;

                axios.post("{:url('forum/getForumList')}", {
                    limit: that.limit,
                    page: that.page,
                    keywords: that.keywords,
                    forum_cate_id:that.forum_cate_id,
                    user_id:"{$Think.session.wechat.id}"
                }).then(function (ret) {
                    if (ret.data.code == 1) {
                        vant.Notify({type: 'danger', message: ret.data.msg});
                    }
                    let data = ret.data.data
                    if (that.page == 1) {
                        that.goodsQiangList = data.data
                    } else {
                        for (var i = 0, len = data.data.length; i < len; i++) {
                            that.goodsQiangList.push(data.data[i])
                        }
                    }

                    that.last_page = data.last_page
                    that.loading = false;
                    that.isLoading = false;
                })
            },
            jumpDetail(forum_id) {
                window.location.href = "{:url('forum/detail')}?forum_id=" + forum_id
            },
            onTabbarChange(index) {
                let url = '';
                switch (index) {
                    case 0:
                        url = "{:url('index/index')}";
                        break;
                    case 1:
                        url = "{:url('shop/index')}";
                        break;
                    case 2:
                        url = "{:url('forum/index')}";
                        break;
                    case 3:
                        url = "{:url('user/index')}";
                        break;
                }
                window.location.href = url;
            },
            del(forum_id,index) {
                let that = this
                vant.Dialog.confirm({
                    title: '提示',
                    message: '确定要删除帖子吗？',
                }).then(() => {
                    // on confirm
                    axios.post("{:url('forum/del')}", {forum_id: forum_id}).then(function (ret) {
                        that.goodsQiangList.splice(index,1)
                    })
                }).catch(() => {
                    // on cancel
                });
            },
            edit(forum_id){
                window.location.href = "{:url('forum/form')}?forum_id="+forum_id
            },
            shopCateChange(forum_cate_id){
                this.finished = false
                this.forum_cate_id = forum_cate_id
                this.page = 0
                this.last_page = 1
                this.onload()
            },
        },
    })
</script>
</body>
</html>
